home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2006 June / PCpro_2006_06.ISO / files / freeware / openvip.exe / {app} / thumbnail.py < prev    next >
Encoding:
Python Source  |  2003-05-25  |  2.0 KB  |  73 lines

  1. #!/usr/bin/env python
  2.  
  3. #
  4. # This file is part of OpenVIP (http://openvip.sourceforge.net)
  5. #
  6. # Copyright (C) 2002-2003
  7. # Michal Dvorak, Jiri Sedlar, Antonin Slavik, Vaclav Slavik, Jozef Smizansky
  8. #
  9. # This program is licensed under GNU General Public License version 2;
  10. # see file COPYING in the top level directory for details.
  11. #
  12. # $Id: thumbnail.py,v 1.7 2003/05/25 09:27:11 vaclavslavik Exp $
  13. #
  14.  
  15. #
  16. # Generates thumbnail image for an input file.
  17. #
  18.  
  19. import openvip, sys
  20. import Image
  21.  
  22. if len(sys.argv) < 5:
  23.     sys.stderr.write('Usage: %s infile outfile height frames\n' % sys.argv[0])
  24.     sys.exit(1)
  25.  
  26. height = int(sys.argv[3])
  27. frames = int(sys.argv[4])
  28.  
  29. lib = openvip.Library()
  30.  
  31. class ThumbMaker:
  32.     def __init__(self):
  33.         self.images = []
  34.         self.all = []
  35.     def add(self, image):
  36.         self.images.append(image)
  37.     def next(self):
  38.         self.all.append(self.images)
  39.         self.images = []
  40.     def save(self, filename):
  41.         frames = len(self.all[0])
  42.         img = Image.new("RGB", (frames*width, len(self.all)*height))
  43.         ypos = 0
  44.         for images in self.all:
  45.             for i in range(0,len(images)):
  46.                 img.paste(images[i], (i*width,ypos))
  47.             ypos += height
  48.         img.save(filename)
  49.  
  50. # NB: video params based on first video track only:
  51. info = lib.get_file_info(sys.argv[1])
  52. if len(info.video_streams) > 0:
  53.     track = info.video_streams[0]
  54.     width = height * track.width / track.height
  55. else:
  56.     track = info.audio_streams[0]
  57.     width = height
  58.  
  59. maker = ThumbMaker()
  60. dst = openvip.DestCallbackPIL(maker.add)
  61.  
  62. for track in info.video_streams:
  63.     task = lib.create_thumbnails_generator(sys.argv[1], track.name,
  64.                                            width, height, frames, dst)
  65.     task.render()
  66.     maker.next()
  67. for track in info.audio_streams:
  68.     task = lib.create_thumbnails_generator(sys.argv[1], track.name,
  69.                                            width, height, frames, dst)
  70.     task.render()
  71.     maker.next()
  72. maker.save(sys.argv[2])
  73.